import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import router from '../router/index'
import Main from "../components/main.vue";
let  Modules=import.meta.glob("../views/*.vue")

const initMenu=defineStore('menu',()=>{
  function getMenu(){
    let  arr=JSON.parse(sessionStorage.getItem("menu"))
    let children=arr.map(item=>{
      return {
        path:item.path,
        component: Modules[`${item.description}`]
      }
    })
    router.addRoute({
      path: '/system',
      name: 'System',
      component:()=>import('../components/main.vue'),
      children:[...children]
    })
    
    router.addRoute(
      {
        path: '/*',
        component: ()=>import('../views/404.vue')
      }
    )
  }
  return {getMenu}
})
export default initMenu